
package com.thb.pay.core.utils;


import java.util.HashMap;

/**
 * 返回数据

 */
public class R extends HashMap<String, Object> {
    public static final Integer SUCCESS_CODE = 200;
    public static final Integer SYSTEM_CODE = 500;
    public static final Integer UN_AUTHORIZE = 400;
    private static final long serialVersionUID = 1L;
    private static final String SUCCESS_MSG = "SUCCESS";

    private static final String SYSTEM_ERROR_MSG = "未知异常，请联系管理员";

    public R() {
        put("code", SUCCESS_CODE);
        put("msg", SUCCESS_MSG);
        put("timestamp", System.currentTimeMillis());
    }

    public static R error() {
        return error(SYSTEM_CODE, SYSTEM_ERROR_MSG);
    }

    public static R error(String msg) {
        R result = error(SYSTEM_CODE, msg);
        return result;
    }

    public static R error(int code, String msg) {
        R result = new R();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static R ok(String msg) {
        R result = new R();
        result.put("msg", msg);
        return result;
    }

    public static R ok(Object data) {
        R result = new R().put("data", data);
        return result;
    }

    public static R ok() {
        R result = new R();
        return result;
    }

    public static R okData(Object data) {
        R result = new R().put("data", data);
        return result;
    }

    public static R builder() {
        R result = new R();
        return result;
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public R build() {
        return this;
    }
}
